<template>
  <el-dialog
      :visible.sync="drawer"
      :title="title"
      :width="size"
      :before-close="cancel"
      class="my-dialog"
      center
  >
    <div class="content-wrapper">
      <slot />
    </div>

    <div class="dialog-footer">
      <el-button type="primary" @click="save" class="btn">保 存</el-button>
      <el-button @click="cancel" class="btn">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      drawer: false,
      dataObj: ''
    };
  },
  methods: {
    open(dataObj) {
      this.dataObj = dataObj;
      this.drawer = true;
    },
    cancel() {
      this.drawer = false;
      this.dataObj = '';
    },
    save() {
      console.log("保存按钮被点击", this.dataObj); // 调试用
      this.$emit("saveOrUpdate", this.dataObj);
    },
    close() {
      this.drawer = false;
    }
  },
  props: {
    title: {
      type: String,
      default: "" // 取消标题的默认值
    },
    size: {
      type: String,
      default: '800px' // 固定宽度
    }
  }
};
</script>

<style lang="scss" scoped>
.my-dialog {
  .el-dialog {
    border-radius: 8px;
    background-color: #fff;
    padding: 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }

  .el-dialog__header {
    padding: 15px 20px;
    font-size: 18px;
    font-weight: bold;
    border-bottom: 1px solid #eee;
  }

  .content-wrapper {
    padding: 20px;
    color: #333;
    font-size: 14px;
    line-height: 1.6;
  }

  .dialog-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: 20px;
    padding: 10px 20px;
    border-top: 1px solid #eee;
  }

  .btn {
    margin-left: 10px;
    padding: 10px 20px;
    font-size: 14px;
    border-radius: 4px;
    border: none;
    outline: none;
  }

  .btn:hover {
    opacity: 0.8;
  }

  .btn:active {
    transform: translateY(1px);
  }
}
</style>